﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System.Collections.Generic;
using System.Linq;

using ScrumTable.BL.DM.DataManagement;
using ScrumTable.Common.Collections;
using ScrumTable.Common.Data;
using ScrumTable.DL.Data.Generic.Test;
using ScrumTable.DL.Data.Local.Test;
using ScrumTable.DL.Data.Schema.ScrumTableV1;

using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace ScrumTable.BL.DM.Test.DataManagement
{


    /// <summary>
    /// This is the test class for DomainMeta class.
    /// </summary>
    [TestClass]
    public class DomainMetaTest : DomainBaseTest<DomainMeta, MetaSchema>
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the default instance to test.
        /// </summary>
        protected override DomainMeta ToTest
        {
            get
            {
                return Context.Projects[Resources.Project1Id].Types.BugType.FieldMeta.TryGetByName(
                    DataContext.Schema.BugSchema[TestFieldDefinitionSet.SeverityFieldName]);
            }
        }

        #endregion

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new DomainMetaTest instance.
        /// </summary>
        public DomainMetaTest()
        {
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Use TestInitialize to run code before running each test .
        /// </summary>
        [TestInitialize]
        public override void TestInitialize()
        {
            base.TestInitialize();
        }

        /// <summary>
        /// Use TestCleanup to run code after each test has run.
        /// </summary>
        [TestCleanup]
        public override void TestCleanup()
        {
            base.TestCleanup();
        }

        [TestMethod]
        public override void TestParent()
        {
            Assert.IsNotNull(ToTest.Parent);
        }

        [TestMethod]
        public void TestAllowedValues()
        {
            IList<string> expectedMeta = ToTest.AllowedValues.Convert(o => (string)o).ToList();
            int index = 0;

            foreach (string allowedValue in ToTest.AllowedValues)
            {
                Assert.AreEqual(expectedMeta[index++], allowedValue);
            }
        }

        [TestMethod]
        public void TestSuggestedValues()
        {
            DomainMeta suggestedValueField = Context.Projects[Resources.Project1Id].Types.UserStoryType.FieldMeta.TryGetByName(
                    DataContext.Schema.UserStorySchema[TestFieldDefinitionSet.StoryPointsFieldName]);

            Assert.IsNotNull(suggestedValueField);
            Assert.IsNotNull(suggestedValueField.SuggestedValues);
            Assert.AreEqual(11, suggestedValueField.SuggestedValues.ToEnumerable<double>().Count());
        }

        [TestMethod]
        public void TestDefaultValue()
        {
            Assert.IsNotNull(ToTest.DefaultValue);
            Assert.AreEqual(ToTest.DefaultValue, ToTest.DefaultValue);
        }

        [TestMethod]
        public void TestDisplayName()
        {
            // simple tests in order to check if value filled
            Assert.IsNotNull(ToTest.DisplayName);

            // advanced check in order to check if right display name is available
            DomainMeta activatedByToTest = Context.Projects[Resources.Project1Id].Types.TaskType.FieldMeta.TryGetByName(
                    TestFieldDefinitionSet.ActivatedByFieldName);

            Assert.IsNotNull(activatedByToTest);
            Assert.AreEqual("Activated By", activatedByToTest.DisplayName);
        }

        [TestMethod]
        public void TestFieldType()
        {
            Assert.IsNotNull(ToTest.FieldType);
            Assert.AreEqual(ToTest.FieldType, ToTest.FieldType);
        }

        [TestMethod]
        public void TestFieldTypeFormat()
        {
            Assert.AreEqual(DataType.PlainText, ToTest.FieldTypeFormat);
        }

        /// <summary>
        /// Gets the default schema of the instance to test.
        /// </summary>
        /// <param name="schema">Specifies the parent schema instance.</param>
        /// <returns>Returns the retrieved schema instance.</returns>
        protected override MetaSchema GetSchema(ScrumTableV1Schema schema)
        {
            return schema.MetaSchema;
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}
